home *** CD-ROM | disk | FTP | other *** search
/ Clickx 96 / Clickx 96.iso / software / tools / tool / xbmc-10.1.exe / system / shaders / convolution-6x6_d3d.fx < prev    next >
Encoding:
Text File  |  2011-03-08  |  3.5 KB  |  124 lines

  1. /*
  2.  *      Copyright (C) 2005-2010 Team XBMC
  3.  *      http://www.xbmc.org
  4.  *
  5.  *  This Program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2, or (at your option)
  8.  *  any later version.
  9.  *
  10.  *  This Program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with XBMC; see the file COPYING.  If not, write to
  17.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *  http://www.gnu.org/copyleft/gpl.html
  19.  *
  20.  */
  21.  
  22. texture g_Texture;
  23. texture g_KernelTexture;
  24. float2  g_StepXY;
  25.  
  26. sampler RGBSampler =
  27.   sampler_state {
  28.     Texture = <g_Texture>;
  29.     AddressU = CLAMP;
  30.     AddressV = CLAMP;
  31.     MipFilter = LINEAR;
  32.     MinFilter = POINT;
  33.     MagFilter = POINT;
  34.   };
  35.  
  36. sampler KernelSampler =
  37.   sampler_state
  38.   {
  39.     Texture = <g_KernelTexture>;
  40.     AddressU = CLAMP;
  41.     AddressV = CLAMP;
  42.     MipFilter = LINEAR;
  43.     MinFilter = LINEAR;
  44.     MagFilter = LINEAR;
  45.   };
  46.  
  47. struct VS_OUTPUT
  48. {
  49.   float4 Position   : POSITION;
  50.   float2 TextureUV  : TEXCOORD0;
  51. };
  52.  
  53. struct PS_OUTPUT
  54. {
  55.   float4 RGBColor : COLOR0;
  56. };
  57.  
  58. half3 weight(float pos)
  59. {
  60.   return tex1D(KernelSampler, pos).rgb;
  61. }
  62.  
  63. half3 pixel(float xpos, float ypos)
  64. {
  65.   return tex2D(RGBSampler, float2(xpos, ypos)).rgb;
  66. }
  67.  
  68. half3 getLine(float ypos, float3 xpos1, float3 xpos2, half3 linetaps1, half3 linetaps2)
  69. {
  70.   return
  71.     pixel(xpos1.r, ypos) * linetaps1.r +
  72.     pixel(xpos1.g, ypos) * linetaps2.r +
  73.     pixel(xpos1.b, ypos) * linetaps1.g +
  74.     pixel(xpos2.r, ypos) * linetaps2.g +
  75.     pixel(xpos2.g, ypos) * linetaps1.b +
  76.     pixel(xpos2.b, ypos) * linetaps2.b;
  77. }
  78.  
  79. PS_OUTPUT CONVOLUTION6x6(VS_OUTPUT In)
  80. {
  81.   PS_OUTPUT OUT;
  82.  
  83.   float2 pos = In.TextureUV + g_StepXY * 0.5;
  84.   float2 f = frac(pos / g_StepXY);
  85.  
  86.   half3 linetaps1   = weight((1.0 - f.x) / 2.0);
  87.   half3 linetaps2   = weight((1.0 - f.x) / 2.0 + 0.5);
  88.   half3 columntaps1 = weight((1.0 - f.y) / 2.0);
  89.   half3 columntaps2 = weight((1.0 - f.y) / 2.0 + 0.5);
  90.  
  91.   // kernel generation code made sure taps add up to 1, no need to adjust here.
  92.  
  93.   float2 xystart = (-2.0 - f) * g_StepXY + In.TextureUV;
  94.   float3 xpos1 = float3(
  95.       xystart.x,
  96.       xystart.x + g_StepXY.x,
  97.       xystart.x + g_StepXY.x * 2.0);
  98.   float3 xpos2 = half3(
  99.       xystart.x + g_StepXY.x * 3.0,
  100.       xystart.x + g_StepXY.x * 4.0,
  101.       xystart.x + g_StepXY.x * 5.0);
  102.  
  103.   OUT.RGBColor.rgb = getLine(xystart.y                   , xpos1, xpos2, linetaps1, linetaps2) * columntaps1.r +
  104.                      getLine(xystart.y + g_StepXY.y      , xpos1, xpos2, linetaps1, linetaps2) * columntaps2.r +
  105.                      getLine(xystart.y + g_StepXY.y * 2.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.g +
  106.                      getLine(xystart.y + g_StepXY.y * 3.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.g +
  107.                      getLine(xystart.y + g_StepXY.y * 4.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.b +
  108.                      getLine(xystart.y + g_StepXY.y * 5.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.b;
  109.  
  110.   OUT.RGBColor.a = 1.0;
  111.   return OUT;
  112. }
  113.  
  114. technique SCALER_T
  115. {
  116.   pass P0
  117.   {
  118.     PixelShader  = compile ps_3_0 CONVOLUTION6x6();
  119.     ZEnable = False;
  120.     FillMode = Solid;
  121.     FogEnable = False;
  122.   }
  123. };
  124.